window.sentlog = window.sentlog || {referrer:false};
window.site_name = window.site_name || 'M58';
window.page_type = window.page_type || 'NA';
window.post_count = window.post_count || -1;
window.tgreg = window.tgreg || -1;
window._trackURL = window._trackURL || 'NA';
window._trackParams = window._trackParams || 'NA';
var referrer = encodeURIComponent(document.referrer);


(function(){
$("[tongji_tag]").bind('click', function() {var tongji_tag = $(this).attr("tongji_tag");clickLog('from='+tongji_tag);});
})();


(function(){
var pageT = _trackURL || 'NA';
if(pageT.indexOf("\'pagetype\':\'home\'") !=-1){
$("[href]").bind('click', function(e) {var href = $(this).attr("href");var tagY = $(this).offset().top;var tagX = $(this).offset().left;var mouseX = e.pageX;var mouseY = e.pageY;clickLog('from=heatmap:'+href+'&tagX='+tagX+'&tagY='+tagY+'&mouseX='+mouseX+'&mouseY='+mouseY);});}
})();









if (!sentlog.referrer) {
	_trackParams = format_trackParams(_trackParams);
	_trackParams = encodeURIComponent(_trackParams);
	var logmsg = "tag=pvstatall&referrer="+referrer+"&type="+page_type+"&post_count="+post_count + "&_trackParams=" + _trackParams;
	if (page_type=='detail') {
		try{
			logmsg = logmsg + '&userid='+____json4fe.userid;
			if ('phone' in ____json4fe) logmsg = logmsg + '&huzhuan='+____json4fe.phone;
			if (tgreg > 0) logmsg = logmsg + '&tgreg='+tgreg;
		}catch(e){}
	}
	try{
		if ('version' in ____json4fe) logmsg = logmsg + '&version='+____json4fe.version;
		if ('smsc' in ____json4fe) logmsg = logmsg + '&smsc='+____json4fe.smsc;
		if ('start' in ____json4fe) logmsg += '&loadtime='+((new Date()).getTime()-____json4fe.start);
		if ('supplycount' in ____json4fe){
			for(var attr in ____json4fe.supplycount){
				logmsg = logmsg + '&supplycount.'+attr+'='+____json4fe.supplycount[attr];
			}
		}
	}catch(e){}
        try{logmsg = logmsg + '&window_size='+document.documentElement.clientWidth+'x'+document.documentElement.clientHeight;}catch(e){}
	if (_trackURL != 'NA') logmsg = logmsg + '&trackURL='+_trackURL;
	try{
		var m_ga_utma = getcookie('__utma');

        var m_cookieuid = getcookie('cookieuid');
        var utm_source = getcookie('utm_source');   
        var utm_campaiqn=getcookie('utm_campaiqn');
            
    
        if(m_ga_utma && m_ga_utma != ''){
            logmsg = logmsg + '&_ga_utma=' + m_ga_utma;
        }   





             logmsg = logmsg + '&utm_source=' + utm_source;


        if (utm_campaiqn.indexOf("\"")){
             logmsg=logmsg + '&utm_campaiqn=';

        }   
        else
        {       
              logmsg = logmsg + '&utm_campaiqn=' + utm_campaiqn;
        }   





	}catch(e){}
	ajaxlog_new(logmsg);

}
function setcookie(name,val,days){
	var exp = new Date();
	exp.setTime(exp.getTime() + days*86400000);
	document.cookie = name + '=' + escape(val) + ';expires=' + exp.toGMTString();
}
function getcookie(name){
	var arr, reg=new RegExp("(^| )" + name + "=([^;]*)(;|$)");
	if(arr = document.cookie.match(reg)){
		return unescape(arr[2]);
	}
	return '';
}
function ajaxsend(url){
	var img = new Image();
	img.src = url;
}

function ajaxlog_new(log){
	var rand_log_id = Math.random();
	ajaxsend(document.location.protocol+"//tracklog.58.com/m/empty.js.gif?site_name="+site_name+"&"+log+"&rand_id="+rand_log_id);
}


function format_trackParams(paramContent) {
	if(paramContent == "NA") {
		return paramContent;
	}
	try{
		var _trackArrParams = [];
		for(var i = 0, ln = paramContent.length; i < ln; i++){
			_trackArrParams.push(paramContent[i].I + ":" + paramContent[i].V.replace(/\|/g,"*"));
		}
		return _trackArrParams.join("@@");
	}catch(e){
		return "error";
	}
}

function clickLog(log){
	ajaxsend(document.location.protocol+"//tracklog.58.com/m/click/empty.js.gif?site_name="+site_name+"&tag=pvsiters&"+log+"&trackURL="+_trackURL+"&rand="+Math.random());
}



function ajaxlogr(log){
	ajaxsend(document.location.protocol+"//tracklog.58.com/m/click/empty.js.gif?site_name="+site_name+"&"+log+"&trackURL="+_trackURL+"&rand="+Math.random());
}
